﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mobile;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.MobileControls;
using DECOR.BL.BE;
using DECOR.BL.BC;
using System.Collections.Generic;
using CM.BL.BE;

namespace MobileWebApp
{
    public partial class login : MobilePage
    {
        protected void Page_PreRender(object sender, EventArgs e)
        {
            Response.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n");
            //<html xmlns="http://www.w3.org/1999/xhtml" >
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnIngresar_Click(object sender, EventArgs e)
        {
            try
            {
                RfcConfigParametersBE objUsuario = new RfcConfigParametersBE();
                objUsuario.UsuarioWEB = txtUsuario.Text.Trim().ToUpper(); //WEBDIST
                objUsuario.PasswordWEB = txtPassword.Text.Trim();
                string valret = UsuarioBC.login(ref objUsuario);
                if (string.IsNullOrEmpty(valret))
                {
                    if (string.IsNullOrEmpty(objUsuario.Uname) || string.IsNullOrEmpty(objUsuario.Passwd))
                    {
                        lblMensaje.Text = "No cuenta con un Usuario SAP asignado.";
                    }
                    else
                    {
                        Session.Timeout = Convert.ToInt32(ParametroBC.Instance.getParamValue("SessionTimeout"));
                        Session["UsuarioWeb"] = objUsuario;
                        PersonaBE objPersona = PersonaBC.Instance.leer(objUsuario.PerNr); //rgutierrez 25.01.2012
                        Response.Redirect(ParametroBC.Instance.getParamValue("MainPage"));
                        CredencialesController.Usuario = objUsuario;
                    }
                }
                else
                {
                    lblMensaje.Text = valret;
                }
            }
            catch (Exception ex)
            {
                lblMensaje.Text = ex.Message;
            }
        }

    }
}

